<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <th:block th:include="include :: header('制作证书')" />
    </head>
    <body>
      <div class="white-bg">
        <div class="wrapper wrapper-content animated fadeInRight ibox-content">
          <form class="form-horizontal m" id="form-license-make">
              <div class="form-group">
                  <label class="col-sm-3 control-label">版本名称：</label>
                  <div class="col-sm-8">
                      <input name="versionname" id="versionname" class="form-control" type="text" required>
                  </div>
                  <label class="col-sm-3 control-label">机器标识：</label>
                  <div class="col-sm-8">
                      <input name="mac" id="mac" class="form-control" type="text" required>
                  </div>
              </div>
              <div class="row">
                  <div class="col-sm-12">
                      <button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
                      <button type="button" class="btn btn-white btn-sm" onclick="delColumn()"><i class="fa fa-minus"> 删除</i></button>
                      <div class="col-sm-12 select-table table-striped">
                          <table id="bootstrap-table" style="table-layout:fixed;"></table>
                      </div>
                  </div>
              </div>
          </form>
        </div>
          <div class="row">
              <div class="col-sm-offset-5 col-sm-10">
                  <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                  <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
              </div>
          </div>
      </div>
        <th:block th:include="include :: footer" />
        <!--    <th:block th:include="include :: bootstrap-table-fixed-columns-js"/>-->
        <!--    <th:block th:include="include :: bootstrap-table-fixed-columns-css"/>-->
        <script th:inline="javascript">
            var prefix = ctx + "toolbox/license";
            function delColumn() {
                sub.editColumn();
                var indexArr = $.table.selectColumns("index");
                if (indexArr.length == 0) {
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }
                var ids = $.table.selectColumns("id");
                console.info(ids.join());
                var arr = [];
                for (var i=0; i<ids.length; i++) {
                    if (ids[i]) {
                        arr.push(ids[i]);
                    }
                }
                if (arr.length == 0) {
                    sub.delColumn();
                }
            }

            function addColumn() {
                var count = $("#" + table.options.id).bootstrapTable('getData').length;
                sub.editColumn();

                $("#" + table.options.id).bootstrapTable('insertRow', {
                    index: count,
                    row: {
                        index: $.table.serialNumber(count),
                        confSchemeId: "",
                        confSchemeCode: "",
                        applexType: "",
                        authType: "",
                        authorizationNum: "",
                        impowerEndTime: "",
                        simultaneouslyCanEditObjNum: "",
                        tenantSpaceId: ""
                    }
                });
            }

            function submitHandler() {
                if ($.validate.form()) {
                    var info = {};
                    info["branchName"] = $("input[name='versionname']").val();
                    info["mac"] = $("input[name='mac']").val();
                    var infoMap = {};
                    $("#bootstrap-table tr").each(function(index){
                        if(index === 0) {
                            // 当前行为表头，跳过
                            return true; // continue
                        }
                        var obj = {};
                        $(this).find("input").not("[type='checkbox'],[type='radio'],[name*='index']").each(function(){
                            var name = $(this).attr("name").split(".")[1];
                            obj[name] = $(this).val();
                        });
                        infoMap[obj["confSchemeId"]]=obj;
                    });
                    info["info"] =infoMap;
                    $.ajax({
                        url: "http://code.suzhi.link:8070/license/create",
                        type: "post",
                        dataType: "json",
                        contentType:"application/json",
                        data: JSON.stringify(info),
                        success: function(data){
                            console.log(data);
                        }
                    });
                }
            }

            $(function() {
                var options = {
                    pagination: false,
                    showSearch: false,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    sidePagination: "client",
                    fixedColumns: true,
                    fixedNumber: 5,
                    columns: [{
                        checkbox: true
                    },
                        {
                            field: 'index',
                            align: 'center',
                            title: "序号",
                            width: 50,
                            formatter: function (value, row, index) {
                                var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                                return columnIndex + $.table.serialNumber(index);
                            }
                        },
                        {
                            field: 'confSchemeId',
                            title: '配置方案ID',
                            width: 100,
                            formatter: function(value, row, index) {
                                var html = $.common.sprintf("<input class='form-control' type='text' name='fieldInfoList[%s].confSchemeId'>", index);
                                return html;
                            }
                        },
                        {
                            field: 'confSchemeCode',
                            title: '配置方案CODE',
                            width: 100,
                            formatter: function(value, row, index) {
                                var html = $.common.sprintf("<input class='form-control' type='text' name='fieldInfoList[%s].confSchemeCode'>", index);
                                return html;
                            }
                        },
                        {
                            field: 'applexType',
                            align: 'center',
                            title: '应用实例类型',
                            width: 200,
                            formatter: function(value, row, index) {
                                var html = $.common.sprintf("<input class='form-control' type='text' name='fieldInfoList[%s].applexType'>", index);
                                return html;
                            }
                        },
                        {
                            field: 'authType',
                            align: 'center',
                            title: '授权类型',
                            width: 200,
                            formatter: function(value, row, index) {
                                var html = $.common.sprintf("<input class='form-control' type='text' name='fieldInfoList[%s].authType'>", index);
                                return html;
                            }
                        },
                        {
                            field: 'authorizationNum',
                            align: 'center',
                            title: '授权数量',
                            width: 200,
                            formatter: function(value, row, index) {
                                var html = $.common.sprintf("<input class='form-control' type='text' name='fieldInfoList[%s].authorizationNum'>", index);
                                return html;
                            }
                        },
                        {
                            field: 'impowerEndTime',
                            align: 'center',
                            title: '授权结束时间',
                            width: 200,
                            formatter: function(value, row, index) {
                                var html = $.common.sprintf("<input class='form-control' type='text' name='fieldInfoList[%s].impowerEndTime'>", index);
                                return html;
                            }
                        },
                        {
                            field: 'simultaneouslyCanEditObjNum',
                            align: 'center',
                            title: '同时可以编辑应用对象的数量',
                            width: 200,
                            formatter: function(value, row, index) {
                                var html = $.common.sprintf("<input class='form-control' type='text' name='fieldInfoList[%s].simultaneouslyCanEditObjNum'>", index);
                                return html;
                            }
                        },
                        {
                            field: 'tenantSpaceId',
                            align: 'center',
                            title: '租户空间ID',
                            width: 200,
                            formatter: function(value, row, index) {
                                var html = $.common.sprintf("<input class='form-control' type='text' name='fieldInfoList[%s].tenantSpaceId'>", index);
                                return html;
                            }
                        }]
                };
                $.table.init(options);
            })
        </script>

    </body>
</html>